package smashedapples.data.oql
{
	import smashedapples.utils.StringUtils;
	
	public class Expression
	{
		
		private var expression:String = "";
		public var property:String;
		public var operator:String;
		public var value:*;
		
		public function Expression( property:String, operator:String, value:* )
		{	
			this.property = property;
			this.operator = operator;
			this.value = value;	
		}
		
		
		
		public function evaluate( item:*, index:int, array:Array ):Boolean
		{
			if( !item.hasOwnProperty( this.property ))
				return false;
			
			var exists:Boolean = false;
			switch( this.operator )
			{
				case "=="	:	exists = ( item[property] ==  this.value ) 	? true : false;		break;
				case "==="	:	exists = ( item[property] === this.value ) 	? true : false;		break;
				case "!="	:	exists = ( item[property] !=  this.value ) 	? true : false;		break;
				case "!=="	:	exists = ( item[property] !== this.value ) 	? true : false;		break;
				case "<"	: 	exists = ( item[property] <   this.value ) 	? true : false; 	break;
				case "<="	: 	exists = ( item[property] <=  this.value ) 	? true : false; 	break;
				case ">"	:	exists = ( item[property] >   this.value )	? true : false; 	break;
				case ">="	:	exists = ( item[property] >=  this.value )	? true : false; 	break;
			}
			
			return exists;
		}

	}
}